相信有不少習慣使用Windows 的使用者, 對於要使用Linux就抱持著恐懼的態度. 而筆者任職的單位中就存在不少這類的人士在
光一個簡單的mount/ umount 指令就可以讓筆者在同一年教了近千次以上 .... 迫不得已的情況下只好 自己寫規則及腳本處理事情
實作開始:
KERNEL!="sd[a-z][0-9]",GOTO="media_by_label_auto_mount_end"
# Import FS infos
IMPORT{program}="/sbin/blkid -o udev -p %N"
# Get a label if present, otherwise specify one
ENV{ID_FS_LABEL}!="", ENV{dir_name}="%E{ID_FS_LABEL}"
ENV{ID_FS_LABEL}=="", ENV{dir_name}="usbhd-%k"
# Global mount options
ACTION=="add", ENV{mount_options}="relatime"
# Filesystem-specific mount options
ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="$env{mount_options},utf8,gid=100,umask=002"
# Mount the device and then run the /usr/local/bin/cplog.sh (must copy to /usr/local/bin , it will works)
ACTION=="add", RUN+="/bin/mkdir -p /media/tsblog", RUN+="/bin/mount -o $env{mount_options} /dev/%k /media/tsblog", RUN+="/usr/local/bin/cplog.sh"
# Clean up after removal (Not run)
ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/umount -l /media/tsblog", RUN+="/bin/rmdir /media/tsblog"
# Exit
LABEL="media_by_label_auto_mount_end"
上頭的行為
# Copy the content of root folder into the tsblog folder in USB key and then safe remove it.
mkdir -p /media/tsblog/tsblog
cp -rv /root/*.log /media/tsblog/tsblog
printf "Copy total log into USB key.\n"
rm -f /media/tsblog/tsblog/fio_pcie.sh
umount /media/tsblog
printf "Safe remove the USB key.\n"
udevadm control --reload-rules
參考資料: